package com.gin.no_gay_alliance.manager.provider;

import androidx.annotation.NonNull;

import com.gin.common.utils.FileIoUtils;
import com.gin.nga.resource.ResourceProvider;
import com.gin.no_gay_alliance.app.MyApplication;
import com.gin.no_gay_alliance.viewmodel.emote.ThirdPartyEmoteCategory;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import okhttp3.Response;

/**
 * 第三方表情分类提供者
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/19 14:20
 **/
public class ThirdPartyEmoteCategoryProvider extends ResourceProvider<ThirdPartyEmoteCategory> {

    public ThirdPartyEmoteCategoryProvider(String url) {
        super(url, MyApplication.app.okHttpClient, ResourceManager.getRecourceCacheFile(generateFilename(url)), TimeUnit.HOURS.toMillis(6));
    }

    @Override
    protected ThirdPartyEmoteCategory readCache(File cacheFile) throws IOException {
        return FileIoUtils.readObj(cacheFile, ThirdPartyEmoteCategory.class);
    }

    /**
     * 将响应转换为指定类型数据的方法
     *
     * @param response 响应
     * @return T
     */
    @Override
    protected ThirdPartyEmoteCategory convert(@NonNull Response response) throws IOException {
        return readJson(response, ThirdPartyEmoteCategory.class);
    }

}
